<?php
// 获得点击医生信息
// header("content-type:text/html;charset=UTF-8");
include_once("a_checkLogin.php");
include_once("a_getLoginInfo.php");
$docID = $_GET["docID"];

function getDocInfo($id)
{
    $connect_DB = mysqli_connect("localhost", "root", "root", "petHospital");
    if (!$connect_DB) {
        die("<script>alert('数据库连接失败！')</script>;history.go(-1);" . mysqli_connect_errno());
    }

    mysqli_query($connect_DB, "SET NAMES UTF8");

    $info = "SELECT * FROM doc_infos JOIN department_infos ON doc_infos.doc_TypeMain = department_infos.department_ID WHERE doc_ID = '" . $id . "'";
    $order = "SELECT * FROM order_infos WHERE doc_ID = '" . $id . "'";
    $order_history = "SELECT * FROM order_history_infos WHERE doc_ID = '" . $id . "'";
    $replay_msg = "SELECT * FROM replay_msg_infos WHERE doc_ID = '" . $id . "'";

    $r_info = mysqli_query($connect_DB, $info);
    $r_order = mysqli_query($connect_DB, $order);
    $r_order_history = mysqli_query($connect_DB, $order_history);
    $r_replay_msg = mysqli_query($connect_DB, $replay_msg);

    if ($r_info && $r_order && $r_order_history && $r_replay_msg) {
        $row_info = mysqli_fetch_object($r_info);

        $order_num = mysqli_num_rows($r_order_history);
        $replay_num = mysqli_num_rows($r_replay_msg);
        $order_history_num = mysqli_num_rows($r_order_history);
        if ($row_info->doc_Accept == 1) {
            $accept = "正常接诊";
        } else {
            $accept = "暂停接诊";
        }
        echo "
        <div class='infos-div'>
            <div class='photo-div'>
                <img src='../public/pic/doc_imgs/" . $row_info->doc_PhotoAddress . "'>
            </div>
            <div class='b-info-list'>
                <p><span>工号ID：</span>" . $row_info->doc_ID . "</p>
                <p><span>医生姓名：</span>" . $row_info->doc_Name . "</p>
                <p><span>所属分类：</span>" . $row_info->department_Name . "</p>
                <p><span>联系电话：</span>" . $row_info->doc_Phone . "</p>
            </div>
            <div class='down-div'>
                <div class='o-info-list'>
                    <p><span>接诊状态：</span>" . $accept . "</p>
                    <p><span>当前受约：</span>" . $order_num . " 位患者</p>
                    <p><span>历史受约：</span>" . $order_history_num . " 次</p>
                    <p><span>留言回复：</span>" . $replay_num . " 条</p>
                </div>
            </div>
        </div>";
    } else {
        echo "<script>alert('查询失败！')</script>;history.go(-1);";
        exit();
    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="../public/pic/f.png" type="image/x-icon">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>管理员·医生信息详情</title>
    <link rel="stylesheet" href="../public/css/bootstrap.min.css">
    <script src="../public/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="../public/css/adm_public.css">
    <link rel="stylesheet" href="css/adminDoctorInfoPage.css">
</head>

<body>
    <header class="fixed-top">
        <nav class="navbar navbar-expand-lg nav-top fixed-top">
            <div class="container-fluid">
                <div class="logo-div">
                    <img src="../public/pic/logo-h-w.png">
                </div>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                        <li class="nav-item">
                            <a class="nav-link" href="admin_PersonBasicInfo.php">个人基本信息</a>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle active" aria-current="page" role="button"
                                data-bs-toggle="dropdown" aria-expanded="false">
                                医生管理
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="admin_AddDoctor.php">新增医生信息</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_SearchDoctorInfo.php">医生信息检索</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_CreateResetKey.php">重置密码密钥</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_DepartmentControl.php">医生科室管理</a></li>
                            </ul>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown"
                                aria-expanded="false">
                                用户信息管理
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="admin_SearchUserInfo.php">用户信息检索</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_DealDelAccount.php">用户注销审核</a></li>
                            </ul>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown"
                                aria-expanded="false">
                                预约管理
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="admin_ControlDepartments.php">预约科室信息管理</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="admin_ControlDieOrders.php">超时信息处理</a></li>
                            </ul>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown"
                                aria-expanded="false">
                                用户主页管理
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="admin_ControlTips.php">健康知识模块管理</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
                <div class="info-div">
                    <p>
                        <b>当前登录： </b>
                        <name>
                            <?php echo $admin_Name; ?>
                        </name>|
                        <a href="admin_Logout.php">退出</a>
                    </p>
                </div>
            </div>
        </nav>
    </header>
    <main>
        <!-- 导航栏 -->
        <div class="main-top-nav">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="li-first">当前位置>>></li>
                    <li class="breadcrumb-item"><a href="javascript:void(0);">医生管理</a></li>
                    <li class="breadcrumb-item"><a href="admin_SearchDoctorInfo.php">医生信息检索</a></li>
                    <li class="breadcrumb-item active"><a href="javascript:void(0);">信息详情</a></li>
                </ol>
                <div class="now-time-div" id="nowtime"></div>
                <script src="../public/js/getnowtime.js"></script>
            </nav>
        </div>

        <div class="main-content-div">
            <div class="doc-info-div">
                <h4>医生详细信息</h4>
                <?php getDocInfo($docID); ?>
                <a href="admin_SearchDoctorInfo.php"><button class="btn btn-primary">返回</button></a>
            </div>
        </div>

    </main>
    <footer>
        <p>&copy; 2025 ANIMAL HOME PET HOSPITAL. All rights reserved.</p>
    </footer>
</body>

</html>